GPATH="/home/swlee4skmt/bin/giza"
NAO="/home/swlee4skmt/bin/nao2giza"
NUM=/home/swlee4skmt/bin/giza/find_nums.pl
GDF=/home/swlee4skmt/bin/giza/GrowDiagFinalV3.pl

#################################
EVAL=`cat ../../info/num-eval.var`
DEV=`cat ../../info/num-dev.var`
TRAIN=`cat ../../info/num-train.var`
ITR=`cat ../now-itr.var`
let TMP1=($EVAL+$DEV)*3
let TMP2=($EVAL+$DEV+$TRAIN)*3
let EVAL=($EVAL)*3
let DEV=($DEV)*3
let TRAIN=($TRAIN)*3

echo "plain2snt"
${GPATH}/plain2snt.out src.SP tgt.SP

echo "mkcls"
${GPATH}/mkcls -m2 -c50 -psrc.SP -Vsrc.SP.classes opt >& mkcls-src.log
${GPATH}/mkcls -m2 -c50 -ptgt.SP -Vtgt.SP.classes opt >& mkcls-tgt.log

echo "run giza src->tgt..."
rm -rf wa-st; mkdir -p wa-st; cd wa-st;
time ${GPATH}/GIZA++ ../giza_st.cfg -O st >& ../giza_st.log
rm -rf *.a3.?  *.A3.?  *.d3.?  *.d4.?  *.D4.?  *.n3.?  *.t3.?  *.p0_3.?
mv st.A3.final ../st-all.giza
cd ..
head -${EVAL} st-all.giza > st-eval.giza
head -${TMP1} st-all.giza | tail -${DEV} >  st-dev.giza
head -${TMP2} st-all.giza | tail -${TRAIN} > st-train.giza

echo "run giza tgt->src..."
rm -rf wa-ts; mkdir -p wa-ts; cd wa-ts
time ${GPATH}/GIZA++ ../giza_ts.cfg -O ts >& giza_ts.log
rm -rf *.a3.?  *.A3.?  *.d3.?  *.d4.?  *.D4.?  *.n3.?  *.t3.?  *.p0_3.?
mv ts.A3.final ../ts-all.giza
cd ..
head -${EVAL} ts-all.giza > ts-eval.giza
head -${TMP1} ts-all.giza | tail -${DEV} > ts-dev.giza
head -${TMP2} ts-all.giza | tail -${TRAIN} > ts-train.giza

echo "Number ST";
perl ${NUM} -1 st-all.giza > st-all.nao
echo "Number TS";
perl ${NUM} -1 ts-all.giza > ts-all.nao

echo "start to symmetrization..."
rm -rf wa-symm; mkdir wa-symm;
perl ${GDF} st-all.nao ts-all.nao src.SP tgt.SP wa-symm

mv wa-symm/INTERSECTION.txt int-all.nao
mv wa-symm/UNION.txt uni-all.nao
mv wa-symm/GROW_DIAG_FINAL.txt gdf-all.nao

${NAO} int-all.nao st-all.giza int-all.giza
head -${EVAL} int-all.giza > int-eval.giza
head -${TMP1} int-all.giza | tail -${DEV} > int-dev.giza
head -${TMP2} int-all.giza | tail -${TRAIN} > int-train.giza

${NAO} uni-all.nao st-all.giza uni-all.giza
head -${EVAL} uni-all.giza > uni-eval.giza
head -${TMP1} uni-all.giza | tail -${DEV} > uni-dev.giza
head -${TMP2} uni-all.giza | tail -${TRAIN} > uni-train.giza

${NAO} gdf-all.nao st-all.giza gdf-all.giza
head -${EVAL} gdf-all.giza > gdf-eval.giza
head -${TMP1} gdf-all.giza | tail -${DEV} > gdf-dev.giza
head -${TMP2} gdf-all.giza | tail -${TRAIN} > gdf-train.giza

if [ ${ITR} == 0 ]; then
	echo -n""
else
	echo "recovering"
	./recov.sh
fi

## delete all
rm -rf wa-st wa-ts wa-symm
rm -rf *.class* *.snt *.vcb
echo done
